/*
 * @Description: 路由跳转
 * @Author: wangwangwang
 * @Date: 2020-10-14 09:34:35
 * @LastEditors: wangwangwang
 * @LastEditTime: 2020-11-18 09:37:18
 */
import Vue from "vue";
import VueRouter from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
Vue.use(VueRouter);
/* 初始路由*/
export const routes = [
  {
    path: "/", //这个表示的是根目录，即一进入的页面
    redirect: "login", //设置页面一进来就显示的页面，即重定向到goods组件，这里写的内容是对应组将的component的值
  },
  {
    path: "/index",
    name: 'index',
    component: () => import(/* webpackChunkName: "pages1" */ './sync/index.vue'),
    meta: {
      title: '同步'
    },
  },
  {
    path: "/login",
    name: 'login',
    component: () => import(/* webpackChunkName: "pages1" */ './views/login.vue'),
    meta: {
      title: '过磅管理'
    },
  },
  {
    path: "/pages",
    name: 'pages',
    component: () => import(/* webpackChunkName: "pages1" */ './views/pages.vue'),
    meta: {
      title: '过磅管理'
    },
  },
];
/* 动态路由*/
export const errroutes = [{
  path: "/404",
  component: () => import(/* webpackChunkName: 'error'*/"@/views/error/error404"),
},
{
  path: "/401",
  component: () => import(/* webpackChunkName: 'error'*/"@/views/error/error401"),
},
{
  path: "*",
  redirect: "/404",
},
];
const router = new VueRouter({
  routes,
});
router.addRoutes(errroutes);
/*进度条配置*/
NProgress.configure({
  easing: "linear",
  speed: 500, // 动画时间
  showSpinner: false, // 不显示转动的小圆圈
});
export default router;
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
    NProgress.start();
  }
  next();
});
router.afterEach(() => {
  NProgress.done();
});